package edu.API基础String.String;

import java.util.Scanner;

public class 案例_用户登录 {
    /*已知用户名和密码，有三次登录机会，登录之后给出相应提示*/
    public static void main(String[] args) {
        //已知正确的
        String username = "admin";
        String password = "123456";
        //循环次数明确，使用for循环
        for (int i = 1; i <=3 ; i++) {
            //键盘录入
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名：");
            String scUsername = sc.nextLine();
            System.out.println("请输入密码：");
            String scPassword = sc.nextLine();

            //比较
            if (username == scUsername && password == scPassword){
                System.out.println("登录成功");
                break;
            }else{
                if (i==3){
                    System.out.println("登录失败，请明天再来");
                }else{
                    System.out.println("登录失败，您还剩余"+(3-i)+"次机会");
                }
            }

        }


    }
}
